package com.dj.merchant.controller;



import com.dj.common.response.ApiResponse;
import com.dj.common.types.CommonResponseCode;

import com.dj.merchant.endpoint.MerchantInfoService;
import com.dj.merchant.model.MerchantInfo;
import com.dj.merchant.model.MerchantParamList;
import com.dj.merchant.service.MerchantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
public class MerchantBaseController implements MerchantInfoService {

    @Autowired
    private MerchantService merchantService;

    @ResponseBody
    public Object createMerchant(@RequestBody MerchantInfo merchantInfo) {
        Object result = merchantService.createMerchant(merchantInfo);
        if (result != "success") {
            return ApiResponse.fail(CommonResponseCode.INVALID_PARAMETERS);
        }
        return ApiResponse.SUCCESS_MESSAGE;
    }

    @ResponseBody
    public Object getMerchantById(@RequestParam("merchantId") Long merchantId) {
        if (merchantId.longValue() == 0 || merchantId == null) {
            return ApiResponse.fail(CommonResponseCode.INVALID_PARAMETERS);
        }
        MerchantInfo merchantInfo = merchantService.getMerchantById(merchantId);
        if (merchantInfo.getApproveStatus()== null) {
            //查询不到此商户
            return ApiResponse.fail(CommonResponseCode.INVALID_PARAMETERS);
        }
        return merchantInfo;
    }

    @ResponseBody
    public List<MerchantInfo> queryBySearch(@RequestBody MerchantParamList merchantParamList) {
        List<MerchantInfo> merchantInfos = merchantService.queryBySearch(merchantParamList);
        System.out.println(merchantInfos);
        return merchantInfos;
    }

    @ResponseBody
    public Integer updateMerchantByExample(@RequestBody MerchantInfo merchantInfo) {
        Integer integer = merchantService.updateMerchantByExample(merchantInfo);
        return integer;
    }
}
